# Contributor: Natanael Copa <ncopa@alpinelinux.org>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=tenacity
pkgver=2.4.2
pkgrel=7
pkgdesc="Multitrack audio editor"
url="https://tenacityaudio.org/"
arch="all"
license="GPL-2.0-or-later"
makedepends="
	alsa-lib-dev
	cmake
	expat-dev
	flac-dev
	jack-dev
	lame-dev
	libid3tag-dev
	libmad-dev
	libogg-dev
	libsndfile-dev
	libvorbis-dev
	samurai
	soundtouch-dev
	soxr-dev
	taglib-dev
	wxgtk3-dev
	ffmpeg4-dev
	"
subpackages="$pkgname-doc $pkgname-lang"
provides="audacity=$pkgver-r$pkgrel"
replaces="audacity"
source="$pkgname-$pkgver.tar.gz::https://github.com/tenacityteam/tenacity/archive/Audacity-$pkgver.tar.gz
	0001-audacity.desktop-force-X11-instead-of-Wayland.patch
	fix-include.patch
	lame.pc
	"

builddir="$srcdir"/tenacity-Audacity-$pkgver

prepare() {
	default_prepare
	# included in src/AboutDialog.cpp but not supplied in source tarball
	touch include/RevisionIdent.h
	# cmake can't find libmp3lame without a .pc file
	cp "$srcdir"/lame.pc "$builddir"/lame.pc
}

build() {
	local _arch
	case "$CARCH" in
		x86) _arch="-DHAVE_SSE=OFF -DHAVE_SSE2=OFF";;
	esac

	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	export WX_CONFIG=wx-config-gtk3
	export PKG_CONFIG_PATH="$PWD:$PKG_CONFIG_PATH"
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		$CMAKE_CROSSOPTS \
		$_arch
	cmake --build build
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

sha512sums="
408678dc78cd48517ae58b66bb198d981502d4f465854c9d892f9c808f1161cdbc89f71cd5b048b8310d908cd134f88c37997b351da945ecb471fd4b28809f59  tenacity-2.4.2.tar.gz
43556b6c9f4ea874c313a222c82db8b431f63d3c3cd71c00b4133c82f54d17682dc904de54d7de0f5df371a823adf7584bddab0884487187b047e5dbd8ef6c78  0001-audacity.desktop-force-X11-instead-of-Wayland.patch
f223e5eddca6b8260fe0dae993e4c5f0fbe233544ba2cbadc7b5f80c3d4ff77c86e5abfd2d5edad45cb2af325ccad651b3f74576991d17219d41f6e7139a2d32  fix-include.patch
c82375495c8332c600a636c87db3ef884b86b6e854afab5ff93f1214e96e18f3b8704cdaead017046fda1b0ae29ccf39ff14754aebf4c397911f1506cd7da6f2  lame.pc
"
